<template>
	<gui-page>
		<!-- 页面主体 -->
		<template v-slot:gBody>
			<view>
				<form @submit="submit">
					<view class="gui-margin-top gui-padding-x">
						<text class="gui-h6 gui-secondary-text">求购信息</text>
					</view>
					<view style="height:28rpx;"></view>
					<view class="gui-bg-white gui-dark-bg-level-3 gui-padding-x">
						<view class="gui-form-item gui-border-b">
							<text class="gui-form-label gui-secondary-text">信息名称</text>
							<view class="gui-form-body">
								<input type="text" class="gui-form-input" v-model="formData.qiugou_title"
									placeholder="信息名称" />
							</view>
						</view>
					</view>

					<view class="gui-bg-white gui-dark-bg-level-3 gui-padding-x">
						<view class="gui-form-item gui-border-b">
							<text class="gui-form-label gui-secondary-text">价格</text>
							<view class="gui-form-body">
								<input type="text" class="gui-form-input" v-model="formData.qiugou_price"
									placeholder="价格" />
							</view>
						</view>
					</view>




					<view class="gui-margin-top gui-padding-x">
						<text class="gui-h6 gui-secondary-text">联系信息</text>
					</view>
					<view style="height:28rpx;"></view>

					<view class="gui-bg-white gui-dark-bg-level-3 gui-padding-x">
						<view class="gui-form-item gui-border-b">
							<text class="gui-form-label gui-secondary-text">联系人姓名</text>
							<view class="gui-form-body">
								<input type="text" class="gui-form-input" v-model="formData.qiugou_name"
									placeholder="联系人姓名" />
							</view>
						</view>
					</view>
					<view class="gui-bg-white gui-dark-bg-level-3 gui-padding-x">
						<view class="gui-form-item gui-border-b">
							<text class="gui-form-label gui-secondary-text">联系人电话</text>
							<view class="gui-form-body">
								<input type="text" class="gui-form-input" v-model="formData.qiugou_phone"
									placeholder="联系人电话" />
							</view>
						</view>
					</view>
					<view class="gui-bg-white gui-dark-bg-level-3 gui-padding-x">
						<view class="gui-form-item gui-border-b">
							<text class="gui-form-label gui-secondary-text">地址</text>
							<view class="gui-form-body">
								<input type="text" class="gui-form-input" v-model="formData.qiugou_address"
									placeholder="地址" />
							</view>
						</view>
					</view>
					<view class="gui-bg-white gui-dark-bg-level-3 gui-padding-x">
						<view class="gui-form-item gui-border-b">
							<text class="gui-form-label gui-secondary-text">微信号</text>
							<view class="gui-form-body">
								<input type="text" class="gui-form-input" v-model="formData.qiugou_wchat"
									placeholder="微信号" />
							</view>
						</view>
					</view>



					<view class="gui-margin-top gui-flex gui-row gui-nowrap gui-justify-content-end gui-padding-x">
						<button type="default" class="gui-button gui-bg-primary gui-noborder" style="width:100%;"
							formType="submit">
							<text class="gui-icons gui-color-white gui-button-text">立即发布</text>
						</button>
					</view>
					<view style="height:60rpx;"></view>
				</form>
			</view>
		</template>
	</gui-page>
</template>
<script>
	export default {
		data() {
			return {
				// 表单数据存储
				formData: {
					qiugou_address: '',
					qiugou_name: '',
					qiugou_phone: '',
					qiugou_price: '',
					qiugou_wchat: '',
					qiugou_title: '',
					user_id: ''
				}

			}
		},
		onLoad() {
			var user = uni.gRequest.checkLogin();

			if (user) {
				this.formData.user_id = user.user_id
			}
		},
		methods: {

			submit: function(e) {

				if (!this.formData.qiugou_title) {
					uni.showToast({
						title: "请输入信息名称"
					});
					return;
				}
				if (!this.formData.qiugou_price) {
					uni.showToast({
						title: "请输入价格"
					});
					return;
				}
				if (!this.formData.qiugou_name) {
					uni.showToast({
						title: "请输入联系人"
					});
					return;
				}
				if (!this.formData.qiugou_phone) {
					uni.showToast({
						title: "请输入电话"
					});
					return;
				}




				uni.gRequest.post("qiugou/add", JSON.stringify(this.formData)).then(x => {

					uni.showToast({
						title: "提交成功、请等待管理员审核"
					});

					uni.navigateBack();
				});
			},
			selectCity() {
				uni.navigateTo({
					url: '/pages/com/selectCity'
				})
			}
		}
	}
</script>
<style scoped>
	.gui-idcard-main {
		margin: 25rpx;
	}

	.gui-idcard-desc {
		line-height: 56rpx;
		font-size: 26rpx;
		padding: 20rpx;
		border-radius: 10rpx;
	}

	.gui-idcard-text {
		line-height: 1.8em;
		margin-top: 30rpx;
	}

	.gui-idcard-items {
		padding: 50rpx;
		border-radius: 10rpx;
		margin-top: 15rpx;
	}

	.gui-idcard-items-image {
		width: 380rpx;
	}
</style>